<template>
  <div class="container">
    <div class="pad-t-10"></div>
    <div class="flex-row panel" v-for="(item, index) in listData" :key="index">
      <div>
        <img class="userinfo-avatar" :src="item.fromMemberAvatarUrl" mode="cover" />
      </div>
      <div class="flex-item flex-col mar-t-10">
        <label>{{item.fromMemberNickname}}</label>
        <label class="font-gray font-13">{{item.createTime}}</label>
      </div>
    </div>
    <template v-if="listData.length===0">
      <div class="nodata" v-if="listDataNone">
        <img v-if="fileSpace" :src="fileSpace + '/images/shop-nodata.png'" class="width-375 height-91" alt="">
        <div class="align-c mar-t-5 font-16 font-color-6">空空如也</div>
      </div>
    </template>
    <van-toast id="van-toast" />
  </div>
</template>

<script>
  import {
    pageAccessLog
  } from '@/api/personal'
  // import {
  //   getMemberInfo
  // } from '@/api/home'
import Toast from '@/../static/components/vant-weapp/toast/toast'
  export default {
    data() {
      return {
        listData: [],
        listDataNone: false,
        listQuery: {
          memberId: '',
          currentPage: 1,
          size: 20
        },
        pullLoad: {
          loading: false,
          finished: false
        }
      }
    },
    onShow() {
      this.listQuery.currentPage = 1
      this.listData = []
      this.listQuery.memberId = this.getCustomerId
      this.initAccessLog()
    },
    onReachBottom() {
      if (!this.pullLoad.finished) {
        this.$utils.showToast({
          title: '数据加载中',
          icon: 'loading'
        })
        this.initAccessLog()
      }
    },
    onPullDownRefresh() {
      this.listQuery.currentPage = 1
      this.listData = []
      this.$utils.showToast({
        title: '数据加载中',
        icon: 'loading'
      })
      this.initAccessLog()
      setTimeout(() => {
        this.$pt.stopPullDownRefresh()
      }, 500)
    },
    methods: {
      initAccessLog() {
        pageAccessLog(this.listQuery).then(response => {
          if (response.isError) return
          this.$pt.hideToast()
          response.data.records.forEach(item => {
            this.listData.push(item)
          })
          if (this.listData.length === 0) {
            this.listDataNone = true
          }
          // 翻页+1
          this.listQuery.currentPage++
          if (this.listData.length === 0 || this.listData.length >= response.data.total) {
            this.pullLoad.finished = true
          }
        }).catch(() => {
        })
      },
      goHome(memberId) {
        Toast('访问功能升级中，敬请期待~')
        // let memberInfo = {}
        // getMemberInfo(memberId).then(response => {
        //   if (response.isError) return
        //   memberInfo = response.data
        //   if (memberInfo.veekrayStatus >= 0) {
        //     this.$utils.setMyId(memberId)
        //     this.$root.$mp.appOptions.query = {}
        //     this.$pt.reLaunch({ url: '/pages/home/main' })
        //   } else {
        //     this.$utils.showToast({ title: '未创建主页' })
        //   }
        // })
      }
    }
  }
</script>

<style scoped lang="less">
  .nodata {
    margin-top: 70px;
    .goSetting {
      margin-top: 60px;
      button {
        width: 133px;
        height: 33px;
        background: #333333;
        line-height: 33px;
        padding: 0;
        color: white;
        font-size: 15px;
      }
    }
  }
  .userinfo-avatar {
    width: 50px;
    height: 50px;
    margin: 10px;
    margin-left: 20px;
    border-radius: 50%;
  }
</style>
